/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-03-11 18:47:55
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-05-14 19:19:12
 * @FilePath: \algorithm\algorithm-training\2025_3_11.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include<bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
#define int long long
//using i128 = __int128_t;
inline int inc(int x, int v, int mod) { x += v;return x >= mod ? x - mod : x; }//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 2e3 + 10, M = 1e5 + 10;

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

int dp[31][31][31][31][31];

void solve()
{
    while(1)
    {
        int n;
        cin >> n;
        if(n == 0) return;
        vector<int>arr(n + 10);
        for(int i = 1; i <= n; i ++) cin >> arr[i];
        dp[0][0][0][0][0] = 1;
        for(int a = 0; a <= arr[1]; a ++)
        {
            for(int b = 0; b <= min(arr[2],a); b ++)
            {
                for(int c = 0; c <= min(arr[3],b); c ++)
                {
                    for(int d = 0; d <= min(arr[4],c); d ++)
                    {
                        for(int e = 0; e <= min(arr[5],d); e ++)
                        {
                            if(a == 0 && b == 0 && c == 0 && d == 0 && e == 0) dp[a][b][c][d][e] = 1;
                            else dp[a][b][c][d][e] = 0;
                            if(a > 0 && a - 1 >= b) dp[a][b][c][d][e] += dp[a - 1][b][c][d][e];
                            if(b > 0 && b - 1 >= c) dp[a][b][c][d][e] += dp[a][b - 1][c][d][e];
                            if(c > 0 && c - 1 >= d) dp[a][b][c][d][e] += dp[a][b][c - 1][d][e];
                            if(d > 0 && d - 1 >= e) dp[a][b][c][d][e] += dp[a][b][c][d - 1][e];
                            if(e > 0) dp[a][b][c][d][e] += dp[a][b][c][d][e - 1];
                        }
                    }
                }
            }
        }
        cout << dp[arr[1]][arr[2]][arr[3]][arr[4]][arr[5]] << endl;
    }

}
signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    int tt;
    // cin >> tt;
    // cin.get();
    tt = 1;
    while (tt--)
    {
        solve();
    }
}